#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <api/libdiseqc/lib_diseqc.h>


#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"

#ifdef SUPPORT_CAS_A
#include "win_com_menu_define.h"
#endif

/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER g_win_motor_limitsetup;

extern CONTAINER 	mlimit_item1;	/* limit(Disable/East/West*/

extern TEXT_FIELD 	mlimit_txt1;
extern TEXT_FIELD 	mlimit_txtbtn_setlimit;
extern TEXT_FIELD 	mlimit_txtbtn_gotoref;

extern MULTISEL	mlimit_sel1;

extern TEXT_FIELD 	mlimit_txtinfo;
extern BITMAP		mlimit_bmpinfo;


static VACTION mlimit_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mlimit_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION mlimit_item_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mlimit_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION mlimit_itembtnref_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mlimit_itembtnref_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION mlimit_itembtnset_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mlimit_itembtnset_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION mlimit_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT mlimit_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define WIN_SH_IDX	  WSTL_WIN_BODYRIGHT_01_HD
#define WIN_HL_IDX	  WSTL_WIN_BODYRIGHT_01_HD
#define WIN_SL_IDX	  WSTL_WIN_BODYRIGHT_01_HD
#define WIN_GRY_IDX  WSTL_WIN_BODYRIGHT_01_HD

#define CON_SH_IDX   WSTL_BUTTON_01_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define CON_HLSUB_IDX	WSTL_BUTTON_02_HD

#define TXT_SH_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define BTN_SH_IDX   WSTL_BUTTON_SHOR_HD
#define BTN_HL_IDX   WSTL_BUTTON_SHOR_HI_HD
#define BTN_SL_IDX   WSTL_BUTTON_01_FG_HD
#define BTN_GRY_IDX  WSTL_BUTTON_SHOR_GRY_HD

#define TXTINFO_SH_IDX   WSTL_BUTTON_02_FG_HD
#define TXTINFO_HL_IDX   WSTL_BUTTON_01_FG_HD
#define TXTINFO_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXTINFO_GRY_IDX  WSTL_BUTTON_07_HD

#define BMPINFO_SH_IDX   WSTL_BUTTON_01_HD
#define BMPINFO_HL_IDX   WSTL_BUTTON_01_HD
#define BMPINFO_SL_IDX   WSTL_BUTTON_01_HD
#define BMPINFO_GRY_IDX  WSTL_BUTTON_01_HD

#ifndef SD_UI
#ifndef SUPPORT_CAS_A
/* define in win_com_menu_define.h already */
#define	W_L     	248
#define	W_T     	98
#define	W_W     	692
#define	W_H     	488
#endif

#define CON_L		(W_L+20)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 60)
#define CON_H		40
#define CON_GAP		12

#define TXT_L_OF  	10
#define TXT_W  		300
#define TXT_H		CON_H
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  	(TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W-320)
#define SEL_H		CON_H
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define LINE_L_OF	0
#define LINE_T_OF  	(CON_H+4)
#define LINE_W		CON_W
#define LINE_H     	4

#define BTN_L		(W_L + 160)
#define BTN_T		(CON_T + (CON_H + CON_GAP)*1 + 30)
#define BTN_W		320
#define BTN_H		40
#define BTN_GAP		12

#define BMPINFO_L1	(BTN_L - BMPINFO_W - 4)
#define BMPINFO_L2 (BTN_L + BTN_W + 4)
#define BMPINFO_T	BTN_T
#define BMPINFO_W	40
#define BMPINFO_H	40

#define TXTINFO_L1	(BMPINFO_L1 - TXTINFO_W)
#define TXTINFO_L2 (BMPINFO_L2 + BMPINFO_W)
#define TXTINFO_T	BTN_T
#define TXTINFO_W	100
#define TXTINFO_H	40
#else
#define	W_L     	105//384
#define	W_T     	57//138
#define	W_W     	482
#define	W_H     	370

#define CON_L		(W_L+20)
#define CON_T		(W_T + 4)
#define CON_W		(W_W - 30)
#define CON_H		32
#define CON_GAP		4

#define TXT_L_OF  	10
#define TXT_W  		180
#define TXT_H		CON_H
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF  	(TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W-320)
#define SEL_H		CON_H
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define LINE_L_OF	0
#define LINE_T_OF  	(CON_H+4)
#define LINE_W		CON_W
#define LINE_H     	4

#define BTN_L		(W_L + 120)
#define BTN_T		(CON_T + (CON_H + CON_GAP)*1 + 30)
#define BTN_W		150
#define BTN_H		32
#define BTN_GAP		10

#define BMPINFO_L1	(BTN_L - BMPINFO_W - 4)
#define BMPINFO_L2 (BTN_L + BTN_W + 4)
#define BMPINFO_T	BTN_T
#define BMPINFO_W	30
#define BMPINFO_H	30

#define TXTINFO_L1	(BMPINFO_L1 - TXTINFO_W)
#define TXTINFO_L2 (BMPINFO_L2 + BMPINFO_W)
#define TXTINFO_T	BTN_T
#define TXTINFO_W	60
#define TXTINFO_H	30

#endif

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,hl,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,hl,CON_SL_IDX,CON_GRY_IDX,   \
    mlimit_item_keymap,mlimit_item_callback,  \
    conobj, ID,1)
    
#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_TXT_BTN_SET(root,varTxt,nxtObj,ID,IDu,IDd,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,IDu,IDd, l,t,w,h, BTN_SH_IDX,BTN_HL_IDX,BTN_SL_IDX,BTN_GRY_IDX,   \
    mlimit_itembtnset_keymap,mlimit_itembtnset_callback,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 0,0,resID,NULL)

#define LDEF_TXT_BTN_REF(root,varTxt,nxtObj,ID,IDu,IDd,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,IDu,IDd, l,t,w,h, BTN_SH_IDX,BTN_HL_IDX,BTN_SL_IDX,BTN_GRY_IDX,   \
    mlimit_itembtnref_keymap,mlimit_itembtnref_callback,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 0,0,resID,NULL)


#define LDEF_TXT_INFO(root,varTxt,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXTINFO_SH_IDX,TXTINFO_HL_IDX,TXTINFO_SL_IDX,TXTINFO_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 0,0,resID,NULL)


#define LDEF_BMP_INFO(root,varBmp,l,t,w,h,icon)		\
  DEF_BITMAP(varBmp,&root,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, BMPINFO_SH_IDX,BMPINFO_HL_IDX,BMPINFO_SL_IDX,BMPINFO_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,icon)


#define LDEF_MSEL(root, varNum, nxtObj, ID, l, t, w, h,style,cur,cnt,ptabl)	\
    DEF_MULTISEL(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    mlimit_item_sel_keymap,mlimit_item_sel_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 20,0,style,ptabl,cur,cnt)
    
#define LDEF_MENU_ITEM_SEL(root,varCon,nxtObj,varTxt,varNum,ID,IDu,IDd,\
						l,t,w,h,resID,style,cur,cnt,ptbl) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HL_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)    \
    LDEF_MSEL(&varCon,varNum,NULL   ,ID, l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cur,cnt,ptbl)

#define LDEF_MENU_ITEM_TXT(root,varCon,nxtObj,varTxt,ID,IDu,IDd,\
						l,t,w,h,resID) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HLSUB_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID)

#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)		\
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    mlimit_keymap,mlimit_callback,  \
    nxtObj, focusID,0)

extern UINT16 limit_opt_strids[];

#define WIN g_win_motor_limitsetup

LDEF_MENU_ITEM_SEL(WIN,mlimit_item1,&mlimit_txtbtn_setlimit,mlimit_txt1,mlimit_sel1, 1, 3, 2, \
		CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, RS_DISEQC12_LIMIT_SETUP, STRING_ID, 0, 3, limit_opt_strids)


LDEF_TXT_BTN_SET(WIN,mlimit_txtbtn_setlimit,&mlimit_txtbtn_gotoref,  2,1,3,\
		BTN_L, BTN_T + (BTN_H + BTN_GAP)*0, BTN_W, BTN_H,RS_DISEQC12_LIMIT_SETUP)

LDEF_TXT_BTN_REF(WIN,mlimit_txtbtn_gotoref,NULL,  3,2,1,\
		BTN_L, BTN_T + (BTN_H + BTN_GAP)*1, BTN_W, BTN_H,RS_DISEQC12_GO_TO_REFERENCE)


LDEF_TXT_INFO(WIN,mlimit_txtinfo,TXTINFO_L1, TXTINFO_T, TXTINFO_W, TXTINFO_H, 0)
LDEF_BMP_INFO(WIN, mlimit_bmpinfo,BMPINFO_L1, BMPINFO_T, BMPINFO_W, BMPINFO_H,0)

LDEF_WIN(WIN,&mlimit_item1, W_L, W_T, W_W, W_H, 1)

#define LIMIT_OPT	(mlimit_sel1.nSel)

#define LIMITOPT_ID	1
#define SETLIMIT_ID	2
#define GOTOREF_ID		3

/*******************************************************************************
*	Local vriable & function declare
*******************************************************************************/
UINT16 limit_opt_strids[] = 
{
	RS_DISEQC12_NO_LIMIT,
	RS_DISEQC12_LIMIT_SETUP_WEST,
	RS_DISEQC12_LIMIT_SETUP_EAST
};

UINT16 limit_btn_strids[] = 
{
	RS_DISEQC12_NO_LIMIT,
	RS_DISEQC12_LIMIT_SETUP_WEST,
	RS_DISEQC12_LIMIT_SETUP_EAST
};


UINT8	motor_move_state;/* 0 - not move, 1-move west, 2-move east */

extern UINT8	antset_cur_tuner;

void win_mlimit_draw_txtinfo(UINT32 pos,UINT32 state);
void win_mlimit_draw_bmpinfo(UINT32 pos,UINT32 state);
// state - 0 normal, 1 - move west, 1-move east
void win_mlimit_draw_info(UINT32 state);

void win_mlimit_limitbtn_setstr(UINT32 stop);
void win_mlimit_limitbtn_draw(UINT32 state);

/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/
static VACTION mlimit_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;

	switch(key)
	{
	case V_KEY_LEFT:
		act = VACT_DECREASE;
		break;
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break;
	default:
		act = VACT_PASS;
	}

	return act;
}

static PRESULT mlimit_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT32 val;
	POBJECT_HEAD pObjRef = (POBJECT_HEAD)&mlimit_txtbtn_gotoref;

	switch(event)
	{
	case EVN_POST_CHANGE:
/*	remove "Go to reference inactive when disable limit selected" 	
		OSD_SetAttr(pObjRef, (LIMIT_OPT==0)? C_ATTR_INACTIVE: C_ATTR_ACTIVE);
*/		
		OSD_DrawObject(pObjRef,C_UPDATE_ALL);

		win_mlimit_draw_info(motor_move_state);
		break;
	}

	return ret;
}


static VACTION mlimit_item_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

	return act;
}

static PRESULT mlimit_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	return ret;	
}


#define VACT_MOVE_WEST (VACT_PASS + 1)
#define VACT_MOVE_EAST (VACT_PASS + 2)
#define VACT_SET_LIMIT (VACT_PASS + 3)
static VACTION mlimit_itembtnset_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;

	switch(key)
	{
	case V_KEY_LEFT:
		act = VACT_MOVE_WEST;
		break;
	case V_KEY_RIGHT:
		act = VACT_MOVE_EAST;
		break;
	case V_KEY_ENTER:
		act = VACT_SET_LIMIT;
		break;
	default:
		act = VACT_PASS;
	}

	return act;
}


static PRESULT mlimit_itembtnset_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;
	struct nim_device *nim_dev;
	SYSTEM_DATA * sys_data = sys_data_get();
    UINT8 back_saved;

	nim_dev= antset_cur_tuner==0? g_nim_dev : g_nim_dev2;
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);

		if(motor_move_state != 0)
			goto STOP_MOVE;

		if(unact == VACT_MOVE_WEST)
		{
			if(LIMIT_OPT==0)
				break;
			
			api_diseqc_drive_motor_west(nim_dev,0);
			motor_move_state = 1;

SET_MOVE_DISPLAY:
			win_mlimit_draw_info(motor_move_state);
			win_mlimit_limitbtn_setstr(1);
			win_mlimit_limitbtn_draw(1);
		}
		else if(unact == VACT_MOVE_EAST)
		{
			if(LIMIT_OPT==0)
				break;

			api_diseqc_drive_motor_east(nim_dev,0);
			motor_move_state = 2;
			
			goto SET_MOVE_DISPLAY;
		}
		else if(unact == VACT_SET_LIMIT)
		{
			sys_data->motor_lmt = LIMIT_OPT;
			switch(LIMIT_OPT)
			{
			case 0:
				api_diseqc_disable_limits(nim_dev,0);
				break;
			case 1:
				api_diseqc_set_west_limit(nim_dev,0);
				break;
			case 2:
				api_diseqc_set_east_limit(nim_dev,0);
				break;
			}
		win_compopup_init(WIN_POPUP_TYPE_SMSG);
		win_compopup_set_msg(NULL, NULL, limit_btn_strids[LIMIT_OPT]);
		win_compopup_open_ext(&back_saved);
		osal_task_sleep(500);
		win_compopup_smsg_restoreback();
		}
		
		break;
	case EVN_UNKNOWNKEY_GOT:
		if(motor_move_state != 0)
		{
STOP_MOVE:
			api_diseqc_halt_motor(nim_dev,0);
			motor_move_state = 0;
			win_mlimit_draw_info(motor_move_state);
			win_mlimit_limitbtn_setstr(0);
			win_mlimit_limitbtn_draw(1);
		}
		break;
	}	

	return ret;
}


#define VACT_GOTOREF (VACT_PASS + 1)
static VACTION mlimit_itembtnref_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;

	switch(key)
	{
	case V_KEY_ENTER:
		act = VACT_GOTOREF;
		break;
	default:
		act = VACT_PASS;
	}

	return act;
}


static PRESULT mlimit_itembtnref_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;
	UINT8 back_saved;

	struct nim_device *nim_dev;

	nim_dev= antset_cur_tuner==0? g_nim_dev : g_nim_dev2;
	
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);
		if(unact == VACT_GOTOREF)
		{
			api_diseqc_goto_reference(nim_dev,0);
			win_compopup_init(WIN_POPUP_TYPE_OK);
			win_compopup_set_msg(NULL, NULL, RS_MSG_MOVE_DISH_TO_REFERENCE_POINT);
            win_compopup_set_btnstr(0, RS_DISEQC12_MOVEMENT_STOP);
			win_compopup_open_ext(&back_saved);
			api_diseqc_halt_motor(nim_dev,0);	
		}
		break;
	}	

	return ret;
}


static VACTION mlimit_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	switch(key)
	{
  	case V_KEY_UP:
        act = VACT_CURSOR_UP;
        break;
    case V_KEY_DOWN:
        act = VACT_CURSOR_DOWN;
		break;
	case V_KEY_EXIT:
	case V_KEY_MENU:
		act = VACT_CLOSE;
		break;
	default:
		act = VACT_PASS;
	}

	return act;	
}

static PRESULT mlimit_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	SYSTEM_DATA * sys_data = sys_data_get();

	switch(event)
	{
	case EVN_PRE_OPEN:
		wincom_open_title(pObj,RS_DISEQC12_LIMIT_SETUP,0);
		
		motor_move_state = 0;
/* The multi-select option should remember previous setting(VACT_SET_LIMIT valid)*/		
		LIMIT_OPT = sys_data->motor_lmt;
		
		OSD_SetContainerFocus(&g_win_motor_limitsetup, LIMITOPT_ID);
/*	remove "Go to reference inactive when disable limit selected" 	
		OSD_SetAttr(&mlimit_txtbtn_gotoref, (LIMIT_OPT==0)? C_ATTR_INACTIVE: C_ATTR_ACTIVE);
*/
		break;
	case EVN_PRE_CLOSE:
		/* Make OSD not flickering */
		*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;	
		sys_data_save(1);
		break;
	case EVN_POST_DRAW:
		win_mlimit_draw_info(motor_move_state);
		break;
	}

	return ret;
}


void win_mlimit_draw_txtinfo(UINT32 pos,UINT32 state)
{
	TEXT_FIELD* txt;
	UINT8 style;
	UINT16 strID;

	txt = &mlimit_txtinfo;

	txt->head.frame.uLeft = (pos == 0)? TXTINFO_L1 : TXTINFO_L2;
	txt->bAlign = (pos == 0)? (C_ALIGN_RIGHT | C_ALIGN_VCENTER) : (C_ALIGN_LEFT | C_ALIGN_VCENTER);

	strID = (state == 3)? 0 :  ( (pos==0)? RS_DISEQC12_MOVEMENT_WEST : RS_DISEQC12_MOVEMENT_EAST);
	OSD_SetTextFieldContent(txt,STRING_ID,strID);
	switch(state)
	{
	case 0:
		style = TXTINFO_SH_IDX;
		break;
	case 1:
		style = TXTINFO_HL_IDX;
		break;
	case 2:
		style = TXTINFO_SL_IDX;
		break;
	case 3:
	default:
		style = TXTINFO_GRY_IDX;		
	}

	OSD_SetColor(txt, style, style, style, style);
	OSD_DrawObject((POBJECT_HEAD)txt,C_UPDATE_ALL);
	 
}

UINT16 bmp_info_icons[][2] = 
{
	{IM_ARROW_02_LEFT,	IM_ARROW_02_SELECT_LEFT},
	{IM_ARROW_02_RIGHT,	IM_ARROW_02_SELECT_RIGHT}
};

void win_mlimit_draw_bmpinfo(UINT32 pos,UINT32 state)
{
	BITMAP* bmp;
	UINT16 icon;

	bmp = &mlimit_bmpinfo;
	bmp->head.frame.uLeft = (pos == 0)? BMPINFO_L1 : BMPINFO_L2;

	if(state>=2)
		icon = 0;
	else
		icon = bmp_info_icons[pos][state];
	
	OSD_SetBitmapContent(bmp, icon);

	OSD_DrawObject((POBJECT_HEAD)bmp,C_UPDATE_ALL);
}

// state - 0 normal, 1 - move west, 1-move east
void win_mlimit_draw_info(UINT32 state)
{
	UINT32 txtl_state,txtr_state,bmpl_state,bmpr_state;

	if(state == 0)
	{
		txtl_state = txtr_state = (LIMIT_OPT==0)? 3 : 0;
		bmpl_state = bmpr_state = (LIMIT_OPT==0)? 3 : 0;
	}
	else if(state == 1)
	{
		txtl_state = 1;
		txtr_state = 0;
		bmpl_state = 1;
		bmpr_state = 0;
	}
	else// if(state == 2)
	{
		txtl_state = 0;
		txtr_state = 1;
		bmpl_state = 0;
		bmpr_state = 1;	
	}

	win_mlimit_draw_txtinfo(0,txtl_state);
	win_mlimit_draw_txtinfo(1,txtr_state);
	win_mlimit_draw_bmpinfo(0,bmpl_state);
	win_mlimit_draw_bmpinfo(1,bmpr_state);
}

void win_mlimit_limitbtn_setstr(UINT32 stop)
{
	TEXT_FIELD* txt;
	UINT16 strid;

	txt = &mlimit_txtbtn_setlimit;
	if(stop)
		strid = RS_DISEQC12_MOVEMENT_STOP;
	else
		strid = RS_DISEQC12_LIMIT_SETUP;//limit_btn_strids[LIMIT_OPT];
	OSD_SetTextFieldContent(txt , STRING_ID, strid);
}

void win_mlimit_limitbtn_draw(UINT32 state)
{
	TEXT_FIELD* txt;
	txt = &mlimit_txtbtn_setlimit;


	if(state == 0)
		OSD_DrawObject((POBJECT_HEAD)txt,C_UPDATE_ALL);
	else
		OSD_TrackObject((POBJECT_HEAD)txt,C_UPDATE_ALL);
}


